package member.order.action;

import m.common.action.ActionRequest;
import m.common.action.Param;
import m.common.action.RequestMethod;
import m.common.model.util.ModelCheckUtil;
import m.common.model.util.ModelQueryCheck;
import m.common.model.util.ModelUpdateUtil;
import m.system.RuntimeData;
import m.system.util.JSONMessage;
import member.base.action.BaseAction;
import member.base.model.UserInfo;
import member.base.service.PageService;
import member.base.util.PowerUtil;
import member.order.model.StorePlan;
import member.order.service.StorePlanService;

@ActionRequest(name = "action/order/storePlan",description = "店铺计划")
public class StorePlanAction extends BaseAction {
    @RequestMethod(description = "获取年度计划")
    public JSONMessage getYear(@Param("year") String year) throws Exception {
        return JSONMessage.success("获取成功")
            .push("model",getService(StorePlanService.class).get(PowerUtil.getStore().getOid(),year));
    }
    @RequestMethod(description = "保存")
    public JSONMessage save(@Param("model") StorePlan model) throws Exception {
        PowerUtil.verifyPower(UserInfo.PowerStore);
        model.setInputStore(PowerUtil.getStore());
        ModelQueryCheck.init(model)
            .checkNotNull("planYear","参数错误")
            .doCheck(false,true);
        ModelCheckUtil.checkUniqueCombine(model,new String[]{"inputStore.oid","planYear"},"参数错误");
        ModelUpdateUtil.saveModel(model);
        //清除首页统计缓存
        RuntimeData.getService(PageService.class).clearMonth(model.getInputStore().getOid());
        return JSONMessage.success("保存成功");
    }
}
